import * as echarts from '../../ec-canvas/echarts'

const app = getApp()

let chart = null

function initChart(canvas, width, height, dpr) {
	chart = echarts.init(canvas, null, {
		width,
		height,
		devicePixelRatio: dpr,
	})

	canvas.setChart(chart)

	const option = {
		xAxis: {
			type: 'category',
			data: ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'],
		},
		yAxis: {
			type: 'value',
		},
		series: [
			{
				data: [820, 932, 901, 934, 1290, 1330, 1320],
				type: 'line',
			},
		],
	}

	chart.setOption(option)

	return chart
}

Page({
	onShareAppMessage: function (res) {
		return {
			title: 'ECharts 可以在微信小程序中使用啦！',
			path: '/pages/index/index',
			success: function () {},
			fail: function () {},
		}
	},
	data: {
		ec: {
			onInit: initChart,
		},
	},
})
